import React from 'react';
import {TIME_DURATION, MEASURE_TYPE, TARGET_TYPE} from '~/utils/const';

const {DAY_TIMESTAMP, ONE_WEEK_DAYS} = TIME_DURATION;

export const week = () => {
    const now = new Date();
    const day = now.getDay();
    const weeks = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    const week = weeks[day];
    return week;
};

export const calculateTime = () => {
    // 本周时间
    let currentTime;
    let startTime;
    let endTime;
    let circleStartTime;
    let circleEndTime;
    const today = new Date();
    // 如果当天为周一时，需要展示上周一至周日的时间
    if (week() === 'Monday') {
        startTime = new Date(today.getTime() - ONE_WEEK_DAYS * DAY_TIMESTAMP);
        endTime = new Date(today.getTime() - DAY_TIMESTAMP);
        currentTime = `${startTime.toLocaleDateString()} - ${endTime.toLocaleDateString()}`;
        circleStartTime = new Date(today.getTime() - ONE_WEEK_DAYS * DAY_TIMESTAMP * 2);
        circleEndTime = new Date(today.getTime() - DAY_TIMESTAMP - ONE_WEEK_DAYS * DAY_TIMESTAMP);
    }
    else {
        const weekNum = today.getDay() || ONE_WEEK_DAYS;
        const currentWeekMonday = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1 - weekNum);
        const yesterday = new Date(today.getTime() - DAY_TIMESTAMP);
        currentTime = `${currentWeekMonday.toLocaleDateString()} - ${yesterday.toLocaleDateString()}`;
        circleStartTime = new Date(currentWeekMonday.getTime() - ONE_WEEK_DAYS * DAY_TIMESTAMP);
        circleEndTime = new Date(circleStartTime.getTime() + 6 * DAY_TIMESTAMP);
    }
    const circleTime = `${circleStartTime.toLocaleDateString()} - ${circleEndTime.toLocaleDateString()}`;
    return {
        currentTime,
        circleTime
    };
};

export const measureTypeMap = new Map([
    [1, {detail: '去除10%截头截尾样本后，所选路径指标时间之和/去除后剩余数据总条数'}],
    [2, {detail: '去除10s以外的异常数据后，所选路径的85分位指标时间（行业对齐标准)'}],
    [3, {detail: '去除10s以外的异常数据后，所选路径的90分位指标时间（主要检测指标）'}],
    [4, {detail: '去除10s以外的异常数据后，所选路径的95分位指标时间（系统稳定性指标）'}]
]);
export const analysisDistributeList = [
    {value: 1, label: '首屏时间分端分布'},
    {value: 6, label: 'TTFB分端分布'},
    {value: 3, label: '服务端响应时间分布'}
];

export const columns = [
    {
        title: '日期',
        dataIndex: 'datetime',
        key: 'datetime',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    },
    {
        title: '业务线',
        dataIndex: 'bizTypeName',
        key: 'bizTypeName',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    },
    {
        title: '应用',
        dataIndex: 'bizName',
        key: 'bizName',
        render: text => (
            <div className="overText" title={text}>
                {text}
            </div>
        )
    },
    {
        title: '路径',
        dataIndex: 'path',
        key: 'path',
        render: text => (
            <div className="overText" title={text}>
                {text}
            </div>
        )
    },
    {
        title: '指标名称',
        dataIndex: 'targetType',
        key: 'targetType',
        render: text => (
            <div title={TARGET_TYPE.get(text)}>
                {TARGET_TYPE.get(text)}
            </div>
        )
    },
    {
        title: '均值',
        dataIndex: 'targetAvg',
        key: 'targetAvg',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    },
    {
        title: '85th',
        dataIndex: 'target85th',
        key: 'target85th',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    },
    {
        title: '90th',
        dataIndex: 'target90th',
        key: 'target90th',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    },
    {
        title: '95th',
        dataIndex: 'target95th',
        key: 'target95th',
        render: text => (
            <div title={text}>
                {text}
            </div>
        )
    }
];

export const distributionText = (
    <div>
        <p>PC: PC站;</p>
        <p>M: M站;</p>
        <p>IPHONE：iOS App内嵌的页面;</p>
        <p>ANDROID: Android App 内嵌的页面;</p>
        <p>WIN: Windows 客户端内嵌的页面;</p>
        <p>MAC: Mac客户端内嵌的页面;</p>
        <p>WX: 微信公众号;</p>
        <p>MP: 小程序页面;</p>
        <p>IPAD: ipad内嵌页面;</p>
    </div>
);
const {currentTime, circleTime} = calculateTime();

export const defaultFeatureData = MEASURE_TYPE.map((item, index) => (
    {
        key: `本周首屏时间-${item.label}`,
        currentTime,
        circleTime,
        detail: measureTypeMap.get(index + 1).detail,
        flag: ''
    }));
export const defaultChartsOption = {
    xAxis: {
        type: 'category',
    },
    yAxis: {
        type: 'value'
    },
    dataset: {
        source: []
    },
    series: []
};
